package crm8000.services

import crm8000.Models.MenuItem
import grails.transaction.Transactional

@Transactional
class MainMenuService {

    def getMainMenuItems() {
		def result = new MenuItem()

		def menuLevel1 = MenuItem.findAllByParentId(null, [sort: "showOrder"])
		
		for (m1 in menuLevel1) {
			result.children.add(m1)
			
			def menuLevel2 = MenuItem.findAllByParentId(m1.menuId, [sort: "showOrder"])
			
			for (m2 in menuLevel2) {
				m1.children.add(m2)
				
				def menuLevel3 = MenuItem.findAllByParentId(m2.menuId, [sort: "showOrder"])
				for (m3 in menuLevel3) {
					m2.children.add(m3)
				}
			}
		}		
		
		return result
    }
}
